<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ReportsController
 *
 * @author Regan
 */
class ReportsController extends AppController {
    public function index()
    {
        if($this->request->data == NULL)
        {
            $popupscript = '';
        }
        else {
            $popupscript = $this->request->data['false']['ReportType'];
            $startdate = $this->request->data['false']['StartDate']['year'] . '-' .
                    $this->request->data['false']['StartDate']['month'] . '-' .
                    $this->request->data['false']['StartDate']['day'];
            $enddate = $this->request->data['false']['EndDate']['year'] . '-' .
                    $this->request->data['false']['EndDate']['month'] . '-' .
                    $this->request->data['false']['EndDate']['day'];
            
            switch($popupscript)
            {
                case 'Import' : 
                    $popupscript = '<script type="text/javascript"> window.open("./Reports/rptimporthistory/' . $startdate . '/' . $enddate . '"); </script>';
                    break;
                case 'Export' :
                    $popupscript = '<script type="text/javascript"> window.open("./Reports/rptexporthistory/' . $startdate . '/' . $enddate . '"); </script>';
                    break;
            }
        }
        
        $this->set('popupscript', $popupscript);
        //$this->set('test', $this->request->data);
    }
    
    public function rptexporthistory($startdate = '', $enddate = '')
    {
        $errormsg = '';
        $this->layout = 'blank';
        
        if($startdate == '' or $enddate == '')
        {
            $errormsg = 'Please provide date parameter';
            $reportData = '';
        }
        else
        {
            $reportData = $this->Report->getExportReportData($startdate, $enddate);
        }
        
        $this->set('errormsg', $errormsg);
        $this->set('StartDate', $startdate);
        $this->set('EndDate', $enddate);
        $this->set('reportData', $reportData);
    }
    
    public function rptimporthistory($startdate = '', $enddate = '')
    {
        $errormsg = '';
        $this->layout = 'blank';
        
        if($startdate == '' or $enddate == '')
        {
            $errormsg = 'Please provide date parameter';
            $reportData = '';
        }
        else
        {
            $reportData = $this->Report->getImportReportData($startdate, $enddate);
        }
        
        $this->set('errormsg', $errormsg);
        $this->set('StartDate', $startdate);
        $this->set('EndDate', $enddate);
        $this->set('reportData', $reportData);
    }
}
